<template>
	<view class="register">
		<view class="loginForm">
			<form @submit="submit">
				<view class="user">
					<input type="text" name="user" placeholder-class="placeholder" value="" placeholder="请输入账号" />
				</view>
				<view class="pass">
					<input type="text" name="pass" placeholder-class="placeholder" value="" placeholder="请输入密码" />
				</view>
				<view class="repeatPass">
					<input type="text" name="repeatPass" placeholder-class="placeholder" value="" placeholder="请输入确认密码" />
				</view>
				<button type="warn" class="submit" form-type="submit">确认</button>
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					user: "",
					pass: "",
					repeatPass:""
				}
			}
		},
		methods: {
			submit(e) {
				this.form.user = e.detail.value.user;
				this.form.pass = e.detail.value.pass;
				this.form.repeatPass = e.detail.value.repeatPass;
				this.request();
			},
			request() {
				if(this.form.pass == this.form.repeatPass){
					uni.request({
						url: 'http://api_dev.wanxikeji.cn/api/register', //仅为示例，并非真实接口地址。
						method: "POST",
						data: {
							name: this.form.user,
							pw: this.form.pass,
						},
						success: (res) => {
							if (res.data.code == 2000) {
								console.log(res)
								uni.navigateTo({
								    url: '/pages/login/login'
								});
							} else {
								console.log(res.data.msg)
							}
						}
					});
				}else{
					console.log("密码不正确")
				}
			
			}
		}
	}
</script>

<style>
	.register {
		margin-top: 80rpx;
		padding: 20rpx;
	}

	.loginForm {
		margin-top: 50rpx;
	}

	.loginForm view {
		margin-top: 30rpx;
		border-bottom: 1rpx solid #ccc;
	}

	.placeholder {
		font-size: 30rpx;
		color: #ccc;
	}

	.submit {
		margin-top: 100rpx;
	}
</style>
